<?php
/**
 * Application level Controller
 *
 * This file is application-wide controller file. You can put all
 * application-wide controller-related methods here.
 *
 * PHP 5
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       app.Controller
 * @since         CakePHP(tm) v 0.2.9
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */

App::uses('Controller', 'Controller');

/**
 * Application Controller
 *
 * Add your application-wide methods in the class below, your controllers
 * will inherit them.
 *
 * @package       app.Controller
 * @link http://book.cakephp.org/2.0/en/controllers.html#the-app-controller
 */
class AppController extends Controller {
	// Para mostrar qual css usar na view
	var $css_array = array();
	public $components = array(
		'Session',
		'Auth' => array(
			'authenticate' => array(
				'Form' => array(
					'userModel' => 'Usuario',
					'fields'=>array(
						'username'=>'email',
						'password'=> 'senha'
					)
				)
			),
			'loginRedirect' => array(
				'controller' => 'usuarios',
				'action' => 'index'
			),
			'logoutRedirect' => '/',
			'loginAction' => array(
				'controller'=>'usuarios',
				'action'=>'login'
			),
			'authError' => 'Você precisa fazer login para acessar essa página',
			'authorize' => 'Controller'
		)
	);
	var $usuarioLogado;

	public function beforeFilter(){
		parent::beforeFilter();
		$this->logado = $this->logado();
		$this->usuarioLogado = $this->Auth->user();
		$this->set('logado', $this->logado());
		$this->set('usuarioLogado', $this->usuarioLogado);
		$this->Auth->deny();
	} 
	
	public function logado(){
		return $this->Auth->loggedIn();
	}
	
	public function isAuthorized($user = null) {
        return  true;
	}
	
	public function beforeRender(){
		parent::beforeRender();
		$this->set('css_array', $this->css_array);
	}
	
	
}
